
var enable_stars = false;

var curPage = "main_page";
var curStarPage = curPage;

function openStarsPage(page){
	if(enable_stars){
		var prevBox = $("#"+curStarPage+" .stars_box");
		$("#"+page+" .stars_box").append(prevBox.html());
		prevBox.empty();
	}
	openPage(page);//$.mobile.changePage( $("#"+page) );
	curStarPage = page;
}

function openPage(page){
	$("#"+curPage+".active").removeClass('active');
	$("#"+page).addClass('active');
	curPage = page;
	if(page == "game_page" && enable_stars){
		startLights();
	} else {
		stopLights();
	}
}

var lightTimer;
var lightInd = 0;

function startLights(){
	lightTimer = setInterval(function(){
		var element = $('.light').eq(lightInd);
		lightInd++;
		if(lightInd > lights.length) lightInd = 0;
		
		if(!element.hasClass("active")){
			element.addClass("active");
		} else {
			element.removeClass("active");
		}			
	}, 200);
}

function stopLights(){
	clearInterval(lightTimer);
}

$(document).ready(function() {
	if(!enable_stars) return;
	
	var dir = retina ? 'img2' : 'img';
	var scale = retina ? 1 : 2;

	for(var i = 0; i < stars.length; i++){
		var star = stars[i];
		$("#"+curStarPage+" .stars_box").append('<img style="position: absolute; left: '+(star.x/scale)+'px; top: '+(star.y/scale)+'px;"'+
			' class="star" src="'+dir+'/stars/'+star.name+'" />');
	}

	//for(var i = 0; i < lights.length; i++){
	for(var i = lights.length-1; i >= 0; i--){
		var light = lights[i];
		$("#game_page .lights_box").append('<img style="position: absolute; left: '+(light.x/scale)+'px; top: '+(light.y/scale)+'px;"'+
			' class="light" src="'+dir+'/'+light.name+'" />');
	}	
	
	var ind = 0;
	setInterval(function(){
		//var rand = Math.floor(Math.random()*stars.length);
		//var element = $('.star').eq(rand);
		
		var element = $('.star').eq(ind);
		ind++;
		if(ind > stars.length) ind = 0;
		
		if(!element.hasClass("active")){
			element.addClass("active");
		} else {
			element.removeClass("active");
		}			
	}, 200);

});

var lights = [
	{name: "lights/1.png", x: 1226, y: 53},
	{name: "stars/10.png", x: 1140, y: 185},
	{name: "lights/2.png", x: 1168, y: 321},
	{name: "stars/10.png", x: 1051, y: 302},
	{name: "lights/3.png", x: 984, y: 387},
	{name: "stars/16.png", x: 910, y: 322},
	{name: "stars/19.png", x: 875, y: 260},
	{name: "stars/33.png", x: 792, y: 294},
	{name: "stars/7.png", x: 692, y: 193},
	{name: "stars/17.png", x: 667, y: 267},
	{name: "stars/36.png", x: 568, y: 251},
	{name: "stars/36.png", x: 475, y: 217},
	{name: "stars/8.png", x: 470, y: 335},
	{name: "lights/4.png", x: 288, y: 231},
	{name: "stars/26.png", x: 308, y: 309},
	{name: "lights/5.png", x: 329, y: 474},
	{name: "stars/29.png", x: 144, y: 482},
	{name: "stars/7.png", x: 286, y: 614},
	{name: "stars/10.png", x: 203, y: 745},
	{name: "stars/23.png", x: 278, y: 851},
	{name: "stars/40.png", x: 247, y: 1012},
	{name: "stars/27.png", x: 417, y: 1005},
	{name: "stars/32.png", x: 427, y: 1200},
	{name: "stars/29.png", x: 640, y: 1139},
	{name: "stars/34.png", x: 922, y: 1187},
	{name: "stars/16.png", x: 1032, y: 1026},
	{name: "stars/8.png", x: 1243, y: 1036},
];

var stars = [
	{name: "1.png", x: 162, y: 13},
	{name: "2.png", x: 103, y: 32},
	{name: "3.png", x: 49, y: 67},
	{name: "4.png", x: 7, y: 125},
	{name: "5.png", x: 0, y: 194},
	{name: "6.png", x: 15, y: 263},
	{name: "7.png", x: 62, y: 322},
	{name: "8.png", x: 125, y: 352},
	
	{name: "9.png", x: 1076, y: 42},
	{name: "10.png", x: 1133, y: 3},
	{name: "11.png", x: 1209, y: 0},
	{name: "12.png", x: 1279, y: 16},
	{name: "13.png", x: 1329, y: 63},
	{name: "14.png", x: 1358, y: 127},
	{name: "15.png", x: 1354, y: 192},
	{name: "16.png", x: 1311, y: 237},
	
	{name: "17.png", x: 1207, y: 1217},
	{name: "18.png", x: 1197, y: 1261},
	{name: "19.png", x: 1179, y: 1329},
	{name: "20.png", x: 1129, y: 1393},
	{name: "21.png", x: 1000, y: 1461},
	{name: "22.png", x: 913, y: 1549},
	{name: "23.png", x: 819, y: 1602},
	{name: "24.png", x: 772, y: 1537},
	{name: "25.png", x: 680, y: 1600},
	{name: "26.png", x: 606, y: 1580},
	{name: "27.png", x: 535, y: 1634},
	{name: "28.png", x: 500, y: 1525},
	{name: "29.png", x: 381, y: 1586},
	{name: "30.png", x: 409, y: 1487},
	{name: "31.png", x: 280, y: 1562},
	{name: "32.png", x: 348, y: 1424},
	{name: "33.png", x: 239, y: 1532},
	{name: "34.png", x: 289, y: 1350},
	{name: "35.png", x: 173, y: 1464},
	{name: "36.png", x: 150, y: 1424},
	{name: "37.png", x: 248, y: 1279},
	{name: "38.png", x: 192, y: 1297},
	{name: "39.png", x: 148, y: 1268},
	{name: "40.png", x: 218, y: 1182},
	{name: "41.png", x: 78, y: 1146},
	{name: "42.png", x: 209, y: 1101},
	{name: "43.png", x: 70, y: 1126},
	{name: "44.png", x: 282, y: 1078},
];